/*
 *  Copyright (C) <2009>  Pavel Vakeš <pavel.vakes@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef GXMailNotify_HEADER
#define GXMailNotify_HEADER

#include <Plasma/Containment>
#include <Plasma/PopupApplet>
#include <Plasma/Svg>
#include <Plasma/ToolTipManager>
#include <Plasma/ToolTipContent>

#include <KConfigDialog>
#include <KConfigGroup>

#include <QPainter>
#include <QTreeWidgetItem>

#include <vector>

#include "account.h"
#include "mail_checker.h"
#include "appearance_dialog.h"
#include "config_dialog.h"
#include "list_account_item.h"
#include "messages_dialog.h"



class PlasmaGXMailNotify: public Plasma::PopupApplet {
	Q_OBJECT
	public:
		PlasmaGXMailNotify(QObject *parent, const QVariantList &args);
		~PlasmaGXMailNotify();

		void createConfigurationInterface(KConfigDialog *parent);

		void paintInterface(QPainter *painter,
				const QStyleOptionGraphicsItem *option,
				const QRect& contentsRect);
		void init();
		QWidget * widget();

	protected:
		virtual void constraintsEvent(Plasma::Constraints constraints);

//	public slots:
//		void toolTipAboutToShow();
//		void toolTipHidden();

	private:
		void dropAccounts();
		void createMailCheckers();
		void dropMailCheckers();

		AppearanceDialog *appearance_dialog;
		ConfigDialog *config_dialog;
		MessagesDialog *messages_dialog;

		std::vector<Account*> accounts;
		std::vector<MailChecker*> mail_checkers;
		bool cfg_tray_icon_size;
		QFont cfg_font;

		int check_messages;
		bool is_check_error;

	private slots:
		void loadConfig();
		void saveConfig();
		void refreshState();
		void startMailCheckers();
		void stopMailCheckers();

		void saveCertificate(Account * account);
};

K_EXPORT_PLASMA_APPLET(gx_mail_notify, PlasmaGXMailNotify)

#endif
